package ro.isdc.navigator.misc.domain;

import java.util.Date;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

public abstract class Entity extends DataObject {
		
	/**
   * Generated Serial Version UID
   */
  private static final long serialVersionUID = -8855711212818493629L;

  /**
	 * Unique internal entity identifier (primary key for non-version 
	 * entities).
	 */
	protected long entityId = -1;
	
	/**
	 * Uniquely identifies the current version of the business entity. This is
	 * also needed for all business entities, for database locking/concurrency
	 * checking purposes.
	 */
	protected int versionNo;
	/**
	 * The user id of the creator of this entity.
	 */
	protected long createdBy = -1;

	/**
	 * Date/time when the entity/version was created.
	 */
	protected Date creationTimestamp;

	/**
	 * The user id for the last change/version of this entity.
	 */
	protected long lastUpdatedBy = -1;

	/**
	 * Date/time of the last change/version creation.
	 */
	protected Date lastUpdateTimestamp;


	/**
	 * @return the entityId
	 */
	public long getEntityId() {
		return entityId;
	}

	/**
	 * @param entityId the entityId to set
	 */
	public void setEntityId(long entityId) {
		this.entityId = entityId;
	}

	/**
	 * @return the versionNo
	 */
	public int getVersionNo() {
		return versionNo;
	}

	/**
	 * @param versionNo the versionNo to set
	 */
	public void setVersionNo(int versionNo) {
		this.versionNo = versionNo;
	}

	/**
	 * @return the createdBy
	 */
	public long getCreatedBy() {
		return createdBy;
	}

	/**
	 * @param createdBy the createdBy to set
	 */
	public void setCreatedBy(long createdBy) {
		this.createdBy = createdBy;
	}

	/**
	 * @return the creationTimestamp
	 */
	public Date getCreationTimestamp() {
		return creationTimestamp;
	}

	/**
	 * @param creationTimestamp the creationTimestamp to set
	 */
	public void setCreationTimestamp(Date creationTimestamp) {
		this.creationTimestamp = creationTimestamp;
	}

	/**
	 * @return the lastUpdatedBy
	 */
	public long getLastUpdatedBy() {
		return lastUpdatedBy;
	}

	/**
	 * @param lastUpdatedBy the lastUpdatedBy to set
	 */
	public void setLastUpdatedBy(long lastUpdatedBy) {
		this.lastUpdatedBy = lastUpdatedBy;
	}

	/**
	 * @return the lastUpdateTimestamp
	 */
	public Date getLastUpdateTimestamp() {
		return lastUpdateTimestamp;
	}

	/**
	 * @param lastUpdateTimestamp the lastUpdateTimestamp to set
	 */
	public void setLastUpdateTimestamp(Date lastUpdateTimestamp) {
		this.lastUpdateTimestamp = lastUpdateTimestamp;
	}

	/**
	 * @see java.lang.Object#equals(Object)
	 */
	public boolean equals(final Object object) {
		if (object == this) {
			return true;
		}
		if (!(object instanceof Entity)) {
			return false;
		}
		Entity rhs = (Entity) object;
		return new EqualsBuilder().append(this.entityId,
				rhs.entityId).isEquals();
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return new HashCodeBuilder(-2103341447, 1374325971).append(
				this.entityId).toHashCode();
	}

  /**
   * @see java.lang.Object#toString()
   */
  public String toString() {
    return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
        .append("createdBy", this.createdBy).append(
            "lastUpdateTimestamp", this.lastUpdateTimestamp).append(
            "lastUpdatedBy", this.lastUpdatedBy).append("versionNo",
            this.versionNo).append("entityId", this.entityId).append(
            "creationTimestamp", this.creationTimestamp).toString();
  }
}
